﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Uaf.Core.Views
{
	public abstract class ViewSiteBase : IViewSite
	{
		protected List<object> Elements
		{
			get;
			private set;
		}

		#region IWorkSpace

		public int Count
		{
			get { return Elements.Count; }
		}

		public object this[int index]
		{
			get { return Elements[index]; }
		}

		public void AddElement(object element)
		{
			if (!Elements.Contains(element))
				Elements.Add(element);
		}

		public void RemoveElement(object element)
		{
			Elements.Remove(element);
		}

		protected ViewSiteBase()
		{
			Elements = new List<object>();
		}

		public event EventHandler<DataEventArgs<object>> ElementActivated;
		protected void OnElementActivated(object element)
		{
			if (ElementActivated != null)
				ElementActivated(this, new DataEventArgs<object>(element));
		}

		public event EventHandler<DataEventArgs<object>> ElementDeactivated;
		protected void OnElementDeactivated(object element)
		{
			if (ElementDeactivated != null)
				ElementDeactivated(this, new DataEventArgs<object>(element));
		}

		#endregion

		#region IEnumerable Members

		public System.Collections.IEnumerator GetEnumerator()
		{
			return Elements.GetEnumerator();
		}

		#endregion
	}
}
